#ifndef GROUP_BY_OPERATION_NODE_H
#define GROUP_BY_OPERATION_NODE_H

#include "OperationNode.h"
#include "SharedArray.h"
#include "AggregationData.h"
#include "RowAggregator.h"

// Groups and aggregates data. Takes ownership of source.
class GroupByOperationNode: public OperationNode {
	public:
		// Takes source of data.
		// Takes ownership of the source.
		GroupByOperationNode(OperationNode* source, SharedArray<int> groupedColumns,
				SharedArray<AggregationData> aggregations);
		~GroupByOperationNode();

		// Pulls data from source, groups it by proper columns and aggregates data.
		virtual SharedArray<Column> pull();

	private:
		OperationNode* _source;
		SharedArray<int> _groupedColumns;
		SharedArray<AggregationData> _aggregations;
		RowAggregator _aggregator;
};

#endif
